// SPU管理相关API
import request from "@/utils/request";
import type {
  SpuListResponse,
  SpuParams,
  BaseSaleAttrList,
  AddOrUpdateSpuParams,
  SpuImageList,
  SpuSaleAttrList,
} from "./model/spuModel";

const enum Api {
  getSpuListApi = "/admin/product",
  getBaseSaleAttrListApi = "/admin/product/baseSaleAttrList",
  addOrUpdateSpu = "/admin/product/saveSpuInfo",
  getSpuImageList = "/admin/product/spuImageList",
  getSpuSaleAttrList = "/admin/product/spuSaleAttrList",
  updateSpu = "/admin/product/updateSpuInfo",
}

/**
 * 获取Spu列表数据
 * @param page 当前页面
 * @param limit 页面条数
 * @param category3Id 三级分类id
 * @returns spuList
 */
export const GetSpuListApi = ({ page, limit, category3Id }: SpuParams) => {
  return request.get<any, SpuListResponse>(
    Api.getSpuListApi + `/${page}/${limit}`,
    {
      params: {
        category3Id,
      },
    }
  );
};

/**
 * 获取基础销售属性列表
 * @returns BaseSaleAttrList
 */
export const GetBaseSaleAttrListApi = () => {
  return request.get<any, BaseSaleAttrList>(Api.getBaseSaleAttrListApi);
};

/**
 * 添加/修改SPU列表
 * @param data
 * @returns
 */
export const AddOrUpdateSpuApi = (data: AddOrUpdateSpuParams) => {
  return request.post<any, null>(Api.addOrUpdateSpu, data);
};

/**
 * 获取SPU 图片列表
 * @param id spuId
 * @returns SpuImageList
 */
export const GetSpuImgListApi = (id: number) => {
  return request.get<any, SpuImageList>(Api.getSpuImageList + `/${id}`);
};

/**
 * 获取SPU销售属性列表
 * @param id spuId
 * @returns SpuSaleAttrList
 */
export const GetSpuSaleAttrListApi = (id: number) => {
  return request.get<any, SpuSaleAttrList>(Api.getSpuSaleAttrList + `/${id}`);
};

/**
 * 更新SPU
 * @param data AddOrUpdateSpuParams
 * @returns null
 */
export const UpdateSpuApi = (data: AddOrUpdateSpuParams) => {
  return request.post<any, null>(Api.updateSpu, data);
};
